use std::net::Ipv4Addr;
use std::net::SocketAddr;
use std::net::SocketAddrV4;
use std::sync::Arc;

use anyhow::Result;
use apikit::doc::ApiDocumentCollector;
use carpet::mock::server::MockServer;
use carpet::mock::server::MockState;
use carpet::server::Server;
use carpet::server::init_log;
use log::info;
use server::TemplateServer;

pub mod api;
pub mod server;
pub mod utils;

#[tokio::main]
async fn main() -> Result<()> {
    let _guard = init_log(None)?;
    let document = ApiDocumentCollector::document();
    for operation in &document.operations {
        info!("{} - {}", operation.method, operation.path);
    }

    let document = Arc::new(document);
    let mocker = MockServer {
        addr: SocketAddr::V4(SocketAddrV4::new(Ipv4Addr::from([0, 0, 0, 0]), 9031)),
        state: MockState::from(document),
    };
    let mocker = mocker.run();

    let server = TemplateServer::default();
    let server = server.run();

    let result = tokio::join!(server, mocker);
    log::info!("server exited: {:?}", result);

    Ok(())
}
